class Solution
{
public:
    long long countBadPairs(vector<int> &nums)
    {
        unordered_map<int, int> goodPairGroups;
        for (int i = 0; i < nums.size(); ++i)
        {
            ++goodPairGroups[nums[i] - i];
        }

        long long result = nums.size() * (nums.size() - 1) / 2;
        for (auto &[_, count] : goodPairGroups)
        {
            result -= count * (count - 1LL) / 2;
        }
        return result;
    }
};